package com.example

import com.example.mapper.ProductMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import kotlin.test.Test
import kotlin.test.assertEquals

@SpringBootTest
class ProductApplicationTests(@Autowired private val productMapper: ProductMapper) {

    @Test
    fun contextLoads() {
    }

    @Test
    fun testOptimisticLocker() {
        val p1 = productMapper.selectById(1)
        val p2 = productMapper.selectById(1)

        // 小李修改价格成功
        p1.price -= 500
        assertEquals(1, productMapper.updateById(p1))

        // 小明修改价格失败
        p2.price -= 500
        assertEquals(0, productMapper.updateById(p2))

    }

}